<?php
    header("Content-type:text/html;charset=utf-8");
    set_item_file();
    function set_item_file(){
        include '../../api/config.php';
        $sql = "SELECT Id,title FROM book WHERE flg=1 ORDER BY id DESC";
        $stmt = $conn->query($sql);
        $stmt->execute();
        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
        $result = $stmt->fetchAll();

        if($result){
            $timer = date("Y-m-d");
            $text = '';
            $maps = '
            <url>
                <loc>https://aijiumai.cn</loc>
                <lastmod>'.$timer.'</lastmod>
                <changefreq>daily</changefreq>
                <priority>1.0</priority>
            </url>
            <url>
                <loc>https://www.aijiumai.cn</loc>
                <lastmod>'.$timer.'</lastmod>
                <changefreq>daily</changefreq>
                <priority>1.0</priority>
            </url>
            <url>
                <loc>https://www.aijiumai.cn/view/item/index.html</loc>
                <lastmod>'.$timer.'</lastmod>
                <changefreq>daily</changefreq>
                <priority>1.0</priority>
            </url>';
            for($i = 0; $i < count($result); $i++){
                $text.='<a href="https://www.aijiumai.cn/view/item/'.$result[$i]['Id'].'.html" target="_blank" title="'.$result[$i]['title'].'">'.$result[$i]['title'].'</a>'; 
                $maps.='
                 <url>
                    <loc>https://www.aijiumai.cn/view/item/'.$result[$i]['Id'].'.html</loc>
                    <lastmod>'.$timer.'</lastmod>
                    <changefreq>daily</changefreq>
                    <priority>1.0</priority>
                </url>';
            };
            set_items($text);//item
            set_sitemap($maps);//网站地图
        };

    };

    function set_items($data){
        // include './comm.php';
        $timer = date("Y-m-d H:i:s");
        $myfile = fopen("../../view/item/index.html", "w") or die("Unable to open file!");
        $text = '<!DOCTYPE html>
        <html>
        
        <head>
            <meta charset="UTF-8">
            <meta
                content="aijiumai.cn,aijiumai,爱尚,最热前端框架,爱尚博客,前端趋势,微信小程序制作,小程序教程,前端怎么做app,app制作,网站开发,靠谱的网站开发,app开发,小程序开发,小程序开发多少钱,app开发多少钱,网站开发多少钱"
                name="Keywords">
            <meta name="description" content="爱尚博客-前端框架收藏夹，只要你打开了爱尚博客，不管你是谁我们就是好朋友了！只要你上了这趟车，从此你就是萌新中的大佬，不再瑟瑟发抖不敢说话啦~" />
            <meta name="viewport"
                content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
            <title>爱尚博客-爱上前端</title>
            <style>
                body,
                html {
                    position: relative;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                    margin: 0;
                    padding: 0;
                    background:url("../../api/get_img.php");
                    /* filter:blur(10px); */
                }
                .box {
                    width: 100%;
                    height: 80%;
                    position: absolute;
                    top: 0;
                    left: 0;
                    overflow-y: auto;
                    z-index: 999;
                }
        
                .box a {
                    display: inline-block;
                    padding: 10px;
                    background: #e0ecf6;
                    color: #000;
                    margin: 10px;
                    text-decoration: none;
                    transition: all 0.5s;
                }
        
                .box a:hover {
                    border-radius: 10px;
                    background: #2196f3;
                    color: #fff;
                }
        
                footer {
                    width: 100%;
                    height: 20%;
                    position: absolute;
                    bottom: 0%;
                    left: 0;
                    /* background: #333; */
                    color: #fff;
                }
        
                footer a {
                    text-decoration: none;
                    color: #fff;
                }
        
                footer img {
                    width: 20px;
                    height: 20px;
                    vertical-align: middle;
                }
        
                footer p {
                    width: 100%;
                    height: 60px;
                    margin: 0 auto;
                    text-align: center;
                    line-height: 60px;
                }
            </style>
        </head>
        
        <body>
        
            <div class="box">
                '.$data.'
            </div>
        
            <footer>
                <p>
                    <img src="https://www.aijiumai.cn/image/beianbgs.png" alt="爱尚博客">
                    <a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011802000140&token=da834af7-3426-45c3-b0b6-437f55b4aa7d"
                        title="粤公网安备-44011802000140号"> 粤公网安备-44011802000140号</a>
                    <a href="http://www.miitbeian.gov.cn/" title="粤ICP备15074775号-1"> 粤ICP备15074775号-1</a>
                </p>
                <p>
                    © 爱尚博客
                    <a href="https://www.aijiumai.cn/sitemap.xml" title="网站地图"> 网站地图</a>
                    <span> 更新时间:'.$timer.'</span>
                </p>
            </footer>
        
        </body>
        <script>
            (function () {
                var bp = document.createElement("script");
                var curProtocol = window.location.protocol.split(":")[0];
                if (curProtocol === "https") {
                    bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
                }
                else {
                    bp.src = "http://push.zhanzhang.baidu.com/push.js";
                }
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(bp, s);
            })();
        </script>
        </html>';
        fwrite($myfile, $text);
        fclose($myfile);
    };


    function set_sitemap($data){
        $myfile = fopen("../../sitemap.xml", "w") or die("Unable to open file!");

        $text = '<?xml version="1.0" encoding="UTF-8"?>
        <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"> 
        '.$data.'
        </urlset>';

        fwrite($myfile, $text);
        fclose($myfile);
    };


